package py.edu.ucom.cadira.net.serializables;

import org.jdom.Document;
import org.jdom.Element;

import py.edu.ucom.cadira.net.XMLSerializable;

public class StartGameRequest implements XMLSerializable {
    private String type = "pruebaXML";
    private Integer mesaId;
	/**
     * @return Returns the type.
     */
    public String getType() {
        return type;
    }

    public StartGameRequest(){
    	
    }
    /**
     * @param type The type to set.
     */
    public void setType(String type) {
        this.type = type;
    }

    public StartGameRequest(int idMesa) {
		super();

	}

public void fromXML(Document xml) {
		
		Element root = xml.getRootElement();
		Element startGameNode = root.getChild("startGame");
		Element tableNode = startGameNode.getChild("table");
		mesaId = Integer.parseInt(tableNode.getAttributeValue("id"));

	}

	public void toXML(Element node) {
		
		Element nodeStartGame = new Element("startGame");
		Element nodeTable = new Element("table");
		nodeTable.setAttribute("id",mesaId.toString());
		nodeStartGame.addContent(nodeTable);
		node.addContent(nodeStartGame);
		
	}
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof StartGameRequest)) {
			return false;
		}
        StartGameRequest otherObj = (StartGameRequest) obj;
		if (otherObj.getType().equals(getType())){
			return true;
		}
		return false;
	}

	/**
	 * @return Returns the idMesa.
	 */
	public int getMesaId() {
		return mesaId;
	}

	/**
	 * @param idMesa The idMesa to set.
	 */
	public void setMesaId(int idMesa) {
		this.mesaId = idMesa;
	}
}